<template>
	<div class="container add_edit">
		<el-form :model="form" ref="ruleForm" label-width="150px">
			<h3 class="margin_b_20">分享</h3>
			<div>
				<el-form-item label="分享标题">
					<el-input v-model="form.share_title" placeholder="请输入分享标题" clearable></el-input>
					<div class="remark_txt">如果不填写，默认为商品名称</div>
				</el-form-item>
				<el-form-item label="分享图标">
					<uni-file-picker v-model="imageValue" fileMediatype="image" returnType="object" :image-styles="imageStyle" @success="imgUpload" @delete="imgDelete" />
					<div class="remark_txt">如果不选择，默认为商品首图</div>
				</el-form-item>
				<el-form-item label="分享描述">
					<el-input type="textarea" :autosize="{ minRows: 3 }" placeholder="请输入分享描述" v-model="form.share_desc"></el-input>
					<div class="remark_txt">如果不填写，默认为商品推广词</div>
				</el-form-item>
			</div>
		</el-form>
	</div>
</template>

<script>
export default {
	data() {
		return {
			form: {
				share_title: '',
				share_img: '',
				share_desc: ''
			},
			imageValue: null,
			imageStyle: {
				height: '150px',
				width: '150px'
			}
		};
	},
	methods: {
		submitData(callback) {
			this.$refs.ruleForm.validate(valid => {
				if (valid) {
					if (typeof callback === 'function') {
						callback(this.form, valid);
					}
				} else {
					if (typeof callback === 'function') {
						callback(this.form, valid);
					}
				}
			});
		},
		getData(callback) {
			this.submitData(callback);
		},
		setData(data) {
			for (const key in this.form) {
				this.form[key] = data[key];
			}

			if (this.form.share_img != '') {
				this.imageValue = {};
				this.imageValue.url = this.form.share_img;
			}
		},
		imgUpload(e) {
			this.form.share_img = e.tempFilePaths[0];
		},
		imgDelete() {
			this.imageValue = null;
			this.form.share_img = '';
		}
	}
};
</script>

<style></style>
